﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PccCommonForC;
using bs_ShowRoom;
namespace ShowRoom.admin
{
    public partial class MenuManager : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user_id"] == null || Session["userId"] == "")
            {
                Response.Redirect("login.aspx");
            }
            if (!IsPostBack)
            {
                GetData();
            }
            if (txtDeleteMenuAdmin.Value != "")
            {
                string Type_ = "2";
                SaveData(txtDeleteMenuAdmin.Value, "", "", "", "", Type_);
               // fnInsUpdImg(txtDeleteMenuAdmin.Value, "", "", "", "", "", "", "2");

                GetData();
            }

        }
        private void GetData()
        {
            string mn_nm = txtMenuName.Text.ToString().Trim();
            string status = ddlActive.SelectedValue.Trim(); ;
            DataTable dt_ = GetMenuAdmin("0",mn_nm, status);
            gvMenu.DataSource = dt_;
            gvMenu.DataBind();
            gvMenu.GridLines = GridLines.None;
        }
        private DataTable GetMenuAdmin(string mn_id,string  mn_nm, string status)
        {
            bs_menu mybs = new bs_menu(ConfigurationManager.ConnectionStrings["ShowRoomConnectionString"].ToString());
            PccMsg myMsg = new PccMsg();
            myMsg.CreateFirstNode("mn_id", mn_id);
            myMsg.CreateFirstNode("mn_nm", mn_nm);
            myMsg.CreateFirstNode("status", status);
            DataSet ds = mybs.DoReturnDataSet("GETMENUADMINBYSEARCH", myMsg.GetXmlStr, "");

            DataTable dt = new DataTable();
            if (ds.Tables.Count > 0)
                dt = ds.Tables[0];

            return dt;

        }

        protected void imgSerach_Click(object sender, ImageClickEventArgs e)
        {
            GetData();
        }

        protected void gvMenu_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView drv = (DataRowView)e.Row.DataItem;
                string mn_id = drv["mn_id"].ToString().Trim();

              
                string active = ((Label)e.Row.FindControl("lblactive")).Text.Trim();
                if (active == "Y")
                    ((Label)e.Row.FindControl("lblactive")).Text = "<img src='img/active.png' />";
                else
                    ((Label)e.Row.FindControl("lblactive")).Text = "<img src='img/inactive.png' />";

                e.Row.Attributes.Add("onmouseover", "setBk(this)");
                e.Row.Attributes.Add("onmouseout", "setBkOut(this)");

                ((Image)e.Row.FindControl("imgEdit")).Style["cursor"] = "pointer";
                ((Image)e.Row.FindControl("imgEdit")).Attributes.Add("onclick", "EditMenuAdmin('" + mn_id + "')");

                ((Image)e.Row.FindControl("imgDelete")).Style["cursor"] = "pointer";
                ((Image)e.Row.FindControl("imgDelete")).Attributes.Add("onclick", "CheckDeletemenuManager('" + mn_id + "')");
            }
        }
        public string SaveData(string mn_id, string mn_nm, string link, string status, string upd_id, string Type)
        {
            bs_menu myBs = new bs_menu(ConfigurationManager.ConnectionStrings["ShowRoomConnectionString"].ToString());
            PccMsg myMsg = new PccMsg();
            myMsg.CreateFirstNode("mn_id", mn_id);
            myMsg.CreateFirstNode("mn_nm", mn_nm);
            myMsg.CreateFirstNode("link", link);
            myMsg.CreateFirstNode("status", status);
            myMsg.CreateFirstNode("upd_id", upd_id);
            myMsg.CreateFirstNode("Type", Type);
            string strXML = myMsg.GetXmlStr;
            string strReturn = myBs.DoReturnStr("INSUPDMENUADMIN", strXML, "");
            myMsg.LoadXml(strReturn);
            return myMsg.Query("Err");
        }

    }
}